package buildIn.observer;

import observer.Display;

import java.util.Observable;
import java.util.Observer;

/**
 * Created with IntelliJ IDEA.
 * User: Alexander
 * Date: 11.07.12
 * Time: 13:58
 * To change this template use File | Settings | File Templates.
 */
public class FirstObserver implements Observer, Display {

    private float temperature;
    private float pressure;
    private float humidity;
    Observable observable;

    public FirstObserver(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    }


    public void update(Observable o, Object arg) {
        if (o instanceof FirstSubject){
            FirstSubject fs = (FirstSubject) o;
            this.temperature = fs.getTemperature();
            this.humidity = fs.getHumidity();
            this.pressure = fs.getPressure();
            display();
        }
    }

    public void display() {
        System.out.println(this.temperature + " " + pressure + " " + humidity);
    }
}
